package com.rexolar.openapi.common;

import com.rexolar.openapi.enums.ErrorCodeEnum;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * @author zhusiyu11000
 * @date 2020-01-17
 */
@Getter
@Setter
@NoArgsConstructor
public class OpenApiResult {
    //平台编码
    public Object code;
    //平台msg
    public String msg;
    //rpc data
    public Object data;

    public OpenApiResult(int errorCode, String msg){
        this.code = errorCode;
        this.msg = msg;
    }

    public OpenApiResult(ErrorCodeEnum errorCodeEnum, Object data){
        this.code = errorCodeEnum.getCode();
        this.msg = errorCodeEnum.getMessage();
        this.data = data;
    }

    public OpenApiResult(ErrorCodeEnum errorCodeEnum){
        this.code = errorCodeEnum.getCode();
        this.msg = errorCodeEnum.getMessage();
    }

    public static OpenApiResult success(Object data){
        OpenApiResult proto =  new OpenApiResult(ErrorCodeEnum.SUCCESS);
        proto.setData(data);
        return proto;
    }

    /**
     */
    public static OpenApiResult fail(ErrorCodeEnum errorCodeEnum){
        return new OpenApiResult(errorCodeEnum);
    }

    public static OpenApiResult fail(int errorCode, String message) {
        return new OpenApiResult(errorCode, message);
    }
}
